home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
usenet
/
st80_pre4
/
CharacterComparing.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
3KB
|
94 lines
" NAME CharacterComparing
AUTHOR Jan Steinman <jans@tekgvs.labs.tek.com>
FUNCTION Add more magnitude funcitionality to Character
ST-VERSIONS Tek 2.3.0
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1.1
DATE May 1988?
SUMMARY
So a Character is a Magnitude, and knows about '<' and '>', then it
should be possible to have an Interval of Characters, right? Well,
sort of. You can create the interval, all right, but you can't do
much with it, because Intervals assume their objects can perform the
arithmetic operations +, -, //, and \\.
The following methods add these capabilities to Characters, and allow
a Character to make an interval with another Character, so you can
enumerate over a range of Characters quickly and easily, or store a
group of Characters in a compact form. (The latter case is handy as a
substitute for literals: ($0 to: $9) instead of '0123456789', or ($A
to: $Z), ($a to: $z) as a substitute for, well, never mind.) Also
added is the capability to compare a Character with some other
Magnitude. This change is som [original text here lost - Ed]
controversial, because Character = is a primitive, and is defined as identity, making equality among Magnitudes impossible.
Jan Steinman - N7JDB
Tektronix Electronic Systems Laboratory
Box 500, MS 50-370, Beaverton, OR 97077
(w)503/627-5881 (h)503/657-7703
"
'From Tektronix Smalltalk-80 version TB2.2.2a of May 05, 1988, 18:14:03.'!
'From Tektronix Smalltalk-80 version TB2.3.0 of Nov 13, 1987, 16:18:35. on 19
April 1988 at 4:00:47 pm'!
!Character methodsFor: 'arithmetic'!
+ aMagnitude
"Return the Character that is <aMagnitude> higher than the receiver. Wrap if the resulting value is not a legal Character value."
^self class value: self asInteger + aMagnitude asInteger \\ CharacterTable size!
- aMagnitude
"Return the Character that is <aMagnitude> lower than the receiver. Wrap if the resulting value is not a legal Character value."
^self class value: self asInteger - aMagnitude asInteger \\ CharacterTable size!
// aMagnitude
"Return the Character who's value is the receiver divided by <aMagnitude>. Wrap if the resulting value is not a legal Character value."
^self class value: self asInteger // aMagnitude asInteger \\ CharacterTable size!
\\ aMagnitude
"Return the Character who's value is the receiver modulo <aMagnitude>. Wrap if the resulting value is not a legal Character value."
^self class value: self asInteger \\ aMagnitude asInteger \\ CharacterTable size! !
!Character methodsFor: 'comparing'!
< aMagnitude
"Answer true if the receiver's value < aMagnitude's value."
^self asInteger < aMagnitude asInteger!
> aMagnitude
"Answer true if the receiver's value > aMagnitude's value."
^self asInteger > aMagnitude asInteger! !
!Character methodsFor: 'converting'!
to: aMagnitude
"Return an Interval over the characters from the receiver to <aMagnitude>. Wrap <aMagnitude> if it is not a legal Character value."
^Interval from: self to: aMagnitude \\ CharacterTable size! !
!Interval methodsFor: 'accessing'!
size
"Return an Integer count of the objects represented by this Interval."
step < 0
ifTrue: [start < stop
ifTrue: [^0]
ifFalse: [^(stop - start // step + 1) asInteger]]
ifFalse: [stop < start
ifTrue: [^0]
ifFalse: [^(stop - start // step + 1) asInteger]]! !